package com.test.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.http.HttpService;

/**
 * web3j客户端
 */
public class Web3JClient {
	
	private static final Logger logger = LoggerFactory.getLogger(Web3JClient.class);
	
    private static String url = "http://127.0.0.1:8545";  // 本地开发环境
//	private static String url = "https://mainnet.infura.io/v3/09ade678f2de415eab21fdb8f8c26328";

    private Web3JClient(){}

    private volatile static Web3j web3j;

    public static Web3j getWeb3j(){
        if(web3j==null){
            synchronized (Web3JClient.class){
                if(web3j==null){
                	logger.info("getWeb3j | url:{}", url);
                    web3j = Web3j.build(new HttpService(url));
                }
            }
        }
        return web3j;
    }

}
